package com.github.prontera.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.prontera.ApiVersion;
import com.github.prontera.common.filter.CurrentUserId;
import com.github.prontera.domain.ClientSign;
import com.github.prontera.model.response.ObjectDataResponse;
import com.github.prontera.service.ClientSignService;
import com.github.prontera.util.Page;


/**
 * 客户端签到
 */
@RestController
@RequestMapping(value = ApiVersion.MANAGE_V1_PREFIX+"/sign")
public class ClientSignController{

	@Autowired
	private ClientSignService clientSignService;
	
	@RequestMapping(value = "find", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<ClientSign>> find(@CurrentUserId Long userId,@RequestBody ClientSign clientSign){
		Page<ClientSign> datas=clientSignService.page(clientSign);
		for (ClientSign clientSign2 : datas.getData()) {
			clientSign2.setNextDayIncomeBean(clientSignService.calSignAmount(clientSign2.getClientId(), clientSign2.getCalBaseAmount()));
		}
		return new ObjectDataResponse<Page<ClientSign>>(datas);
	}
	
	@RequestMapping(value = "update", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Boolean> update(@CurrentUserId Long userId,HttpServletRequest request,@RequestBody  ClientSign clientSign){
		clientSignService.update(clientSign);
		return new ObjectDataResponse<Boolean>(true);
	}
	
	@RequestMapping(value = "add", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Boolean> add(@CurrentUserId Long userId,HttpServletRequest request,@RequestBody  ClientSign clientSign){
		clientSignService.insert(clientSign);
		return new ObjectDataResponse<Boolean>(true);
	}

	@RequestMapping(value = "delete", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Boolean> delete(@CurrentUserId Long userId,@RequestBody  ClientSign clientSign){
		clientSignService.remove(clientSign);
		return new ObjectDataResponse<Boolean>(true);
	}
}
